<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册页面</title>
    <script>
        //验证我的名称是否合法
        function checkName(){
            var name=document.getElementById("USER_NAME").value.trim();
            if(name==''){
                //alert('账号不允许为空');
                document.getElementById("USER_NAME1").innerHTML="账号不允许为空";
                return false;
            }else{
                document.getElementById("USER_NAME1").innerHTML="账号OK";
                return true;
            }
        }

        function checkAge(){
            var age=document.getElementById("USER_AGE").value.trim();
            if(age==''){
                document.getElementById("USER_AGE1").innerHTML="年龄不允许为空";
                return false;
            }else{
                document.getElementById("USER_AGE1").innerHTML="年龄Ok";
                return true;
            }
        }

        function check(){
            var box=document.getElementsByName("sex");
            var sexValue="";
            for(var i=0;i<box.length;i++){
                if(box[i].checked){
                    sexValue=box[i].value;
                    break;
                }
            }
            document.getElementById("USER_SEX").value=sexValue;
            if(checkName()&&checkAge()){
                return true;
            }else{
                return false;
            }
        }
    </script>
</head>
<body>

<form action="insertUser" method="post" onsubmit="return check();">
    <p>名称:<input type="text" name="USER_NAME" maxlength="10" id="USER_NAME" onblur="checkName();"><span id="USER_NAME1">请输入名称</span></p>
    <p>年龄:<input type="text" name="USER_AGE" maxlength="10" id="USER_AGE" onblur="checkAge();"><span id="USER_AGE1">请输入年龄</span></p>
    <p>性别:<input type="radio" value="男" name="sex" checked="checked">男<input type="radio" value="女" name="sex">女</p>
    <input type="hidden" name="USER_SEX" id="USER_SEX">
    <p><input type="submit"><input type="reset"></p>
</form>
</body>
</html>